<div class="container-fluid">
    <div class="wrapper">
        <div class="panel" id="nav">
            <div class="panel-heading"><h3 class="panel-title">查询不良品信息</h3></div>
            <div class="panel-body">
                <form action="__URL__/index" method="get">
                    <div class="container-fluid">
                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">采购单号</span>
                                <input class="form-control" type="text" name="purchaseorder_id">
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">供应商</span>
                                <input type="text" name="supplier" class="form-control" value="">
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">SKU</span>
                                <input class="form-control" type="text" name="sku">
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">站点</span>
                                <select class="chosen-select form-control" tabindex="-1" name="site_id" data-name-group="common">
                                    <option value="" class="empty-opt">-- 请选择 --</option>
                                    <volist name="sites" id="item">
                                        <option value="{$key}">{$item}</option>
                                    </volist>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">采购员</span>
                                <input type="text" name="purchase_man" class="form-control" value="">
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-6  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">质检时间</span>
                                <input class="form-control form-date" type="text" name="check_time_from"
                                       style="cursor:pointer;" readonly>
                                <span class="input-group-addon"><span class="icon-calendar"></span></span>
                                <input class="form-control form-date" type="text" name="check_time_to"
                                       style="cursor:pointer;" readonly>
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">状态</span>
                                <select class="chosen-select form-control" tabindex="-1" name="status"
                                        data-name-group="common">
                                    <option value="" class="empty-opt">-- 请选择 --</option>
                                    <volist name="status" id="item">
                                        <option value="{$key}" >{$item}</option>
                                    </volist>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-3 add-space">
                            <input class="btn btn-primary" type="submit" value="查询">
                            <input class="btn btn-primary" type="button" onclick="reset()" value="重置">
                            <input class="btn btn-primary" type="submit" name="downcsv" value="下载">
                        </div>
                    </div>
                </form>
                <div class="clearfix"></div>
                <hr>
                <table class="table table-striped  table-hover" cellspacing="0" width="100%">
                    <thead>
                    <tr>
                        <th>采购单号</th>
                        <th>质检单号</th>
                        <th>SKU</th>
                        <th>中文名称</th>
                        <th>退税类型</th>
                        <th>站点</th>
                        <th>供应商</th>
                        <th>不合格量</th>
                        <th>质检时间</th>
                        <th>采购员</th>
                        <th>质检不合格原因</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <volist name="result" id="val">
                        <tr>
                            <td>{$val.purchaseorder_id}</td>
                            <td>{$val.check_detail_id}</td>
                            <td>{$val.sku}</td>
                            <td>{$val.sku_name}</td>
                            <td>{$val.export_tax_rebate}</td>
                            <td>{$val.site_id}</td>
                            <td>{$val.supplier}</td>
                            <td>{$val.quantity}</td>
                            <td>{$val.check_time}</td>
                            <td>{$val.purchase_man}</td>
                            <td>{$val.quality_remark}</td>
                            <td>{$val.status}</td>
                            <td>
                                <if condition="$val['status'] eq '未处理'">
                                <button type="button" class="btn btn-xs btn-info b10 edit_detail"  data-toggle="modal" data-target=".btn_edit" data-id="{$val.id}">编辑
                                </button>
                                </if>
                            </td>
                        </tr>
                    </volist>

                </table>
                <div class="clearfix clear"></div>
                <div class="row">
                    <div class="col-md-6 pull-left">
                        <label>每页 20 条记录
                            显示 1 到 20 项，共 {$count}项</label>
                    </div>
                    <div class="col-md-6">
                        <div class="page pull-right" style="padding: 0;margin: 0">
                            {$page}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--编辑---->

<div class="modal fade btn_edit">
    <div class="modal-dialog modal-mg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
                        class="sr-only">关闭</span></button>
                <h4 class="modal-title">编辑</h4>
            </div>
            <div class="modal-body">

                <form class="form-horizontal" action="" method="post" role="form">

                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-md-5 control-label">SKU：</label>

                                    <div class="col-md-7">
                                        <p class="form-control-static sku"></p>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-5 control-label">中文名称：</label>

                                    <div class="col-md-7">
                                        <p class="form-control-static sku_name"></p>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-5 control-label">数量：</label>

                                    <div class="col-md-7">
                                        <p class="form-control-static quantity"></p>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-5 control-label">质检不合格原因：</label>

                                    <div class="col-md-7">
                                        <input type="text" name="quality_remark" class="form-control quality_remark">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>

            </div>
            <div class="modal-footer">
                <input type="hidden" name="id_edit">
                <button type="button" class="btn btn-primary" onclick="edit()">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>

            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        $("input[name='purchaseorder_id']").val("<?php  echo $_GET['purchaseorder_id'];?>");
        $("input[name='supplier']").val("<?php echo $_GET['supplier'];?>");
        $("input[name='sku']").val("<?php echo $_GET['sku'];?>");
        $("input[name='purchase_man']").val("<?php  echo $_GET['purchase_man'];?>");
        $("input[name='check_time_from']").val("<?php  echo $_GET['check_time_from'];?>");
        $("input[name='check_time_to']").val("<?php echo $_GET['check_time_to'];?>");
        $("select[name='site_id']").val("<?php echo $_GET['site_id'];?>");
        $("select[name='status']").val("<?php echo $_GET['status'];?>");
    });

    /**
     * 重置
     * */
    function reset() {
        $('#form_search').find('input').val('');
        $('#form_search').find('select').val('');
    }
    /**
     * 填充编辑数据
     * khq 2017.3.2
     */
    $(".edit_detail").click(function(){
        var id = $(this).attr('data-id');
        if (id) {
            $.get("Warehouse/BadProducts/ajax_select_detail",
                    {id: id},
                    function (data) {
                        var obj = jQuery.parseJSON(data);
                        if (obj.status == 'Y') {
                            $(".sku").html(obj.message.sku);
                            $("input[name=id_edit]").val(id);
                            $(".sku_name").html(obj.message.sku_name);
                            $(".quantity").html(obj.message.quantity);
                            $(".quality_remark").val(obj.message.quality_remark);
                        } else {
                            layer.msg(obj.message, {icon: 5});
                        }
                    });
        }
    });
    /**
     * 编辑明细
     * khq 2017.1.13
     */
    function edit() {
        var id                 = $("input[name=id_edit]").val();
        var quality_remark     = $("input[name=quality_remark]").val();
        $.get("Warehouse/BadProducts//ajax_edit",
                {
                    id: id,
                    quality_remark:quality_remark
                },
                function (data) {
                    if(data.status==0) layer.msg(data.info);
                    var obj = jQuery.parseJSON(data);
                    if (obj.status == 'Y') {
                        layer.msg(obj.message, {icon: 6});
                        window.location.reload();
                    } else {
                        layer.msg(obj.message, {icon: 5});
                    }
                });
    }

    /**
     * @returns {string}
     * 获取搜索条件
     * khq 2017.3.2
     */
    function search_params(){
        var param = '';
        var purchaseorder_id = $("input[name='purchaseorder_id']").val();
        var supplier = $("input[name='supplier']").val();
        var sku = $("input[name='sku']").val();
        var purchase_man = $("input[name='purchase_man']").val();
        var check_time_from = $("input[name='check_time_from']").val();
        var check_time_to = $("input[name='check_time_to']").val();
        var site_id  = $("select[name='site_id']").val();
        var status = $("select[name='status']").val();

        if($.trim(purchaseorder_id) != ''){
            param += "&purchaseorder_id="+$.trim(purchaseorder_id);
        }
        if($.trim(supplier) != ''){
            param += "&supplier="+$.trim(supplier);
        }
        if($.trim(sku) != ''){
            param += "&sku="+$.trim(sku);
        }
        if($.trim(purchase_man) != ''){
            param += "&purchase_man="+$.trim(purchase_man);
        }
        if($.trim(status) != ''){
            param += "&status="+$.trim(status);
        }
        if($.trim(site_id) != ''){
            param += "&site_id="+$.trim(site_id);
        }
        if($.trim(check_time_from) != '' && $.trim(check_time_to) != ''){
            param += "&check_time_from="+$.trim(check_time_from);
            param += "&check_time_to="+$.trim(check_time_to);
        }
        return param;
    }
    function download_csv() {
        var param = search_params();
        window.location.href = '__URL__/index?downcsv=1' + param;
    }

</script>
